package com.homework.note.Controller;

import com.homework.note.Repository.TrashRepository;
import com.homework.note.Service.TrashService;
import com.homework.note.Util.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author htyu
 * @date 2019/3/10
 */
@RestController
@RequestMapping(value = "trash")
public class TrashController {

    @Autowired
    TrashService trashService;

    @Autowired
    TrashRepository trashRepository;

    @GetMapping("list")
    public Message list(){
        return Message.success(trashService.getList());
    }

    @DeleteMapping("delete")
    public Message delete(String trashID){
        try{
            return Message.success(trashService.delete(trashID));
        }catch (RuntimeException e){
            return Message.error("待删除文件不存在");
        }
    }

    @PostMapping("restore")
    public Message restore(String trashID){
        return Message.success(trashRepository.findById(trashID));
    }
}
